package cn.zhangxd.svca.advice;

import cn.zhangxd.svca.exception.MaintenanceException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ControllerExceptionHandler {
	@ExceptionHandler(MaintenanceException.class)
	@ResponseBody
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	//@ResponseStatus(HttpStatus.OK)
	public Map<String, Object> handleUserNotExistException(MaintenanceException ex) {
		Map<String, Object> result = new HashMap<>();
		result.put("id", 1);
		result.put("message", ex.getMessage());
		//result.put("message", "xxxxxxxx");
		return result;
	}
}